package iostream;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class InOutStreamDemo01 {
    public static void main1(String[] args) throws IOException {
        //创建一个文件对象，将数据写入到文件中
        File file = new File("D:\\develop\\idea\\javase-code\\day09-code\\src\\file\\new 1.txt");

        //追加
        FileOutputStream fos = new FileOutputStream(file,true);

        //单个字节写入
        fos.write(65);
        fos.write(97);

        //批量写入
        byte[] bytes = {65, 66, 67, 68, 69};
        fos.write(bytes);

        String s = "hello world";
        byte[] bytes1 = s.getBytes();
        fos.write(bytes1);
        //追加
        fos.write("国标".getBytes(StandardCharsets.UTF_8));

        //关闭流
        fos.close();
    }
    public static void main(String[] args) throws IOException {

        //创建一个文件对象，将数据写入到文件中
        File file = new File("day09-code/src/file/demo.txt");
        //创建流管道,添加覆盖
        FileOutputStream fos1 = new FileOutputStream(file);
        //追加
        FileOutputStream fos = new FileOutputStream(file,true);

        //单个字节写入
        fos.write(65);


        //批量写入
        byte[] bytes = {65, 66, 67, 68, 69};
        fos.write(bytes);

        String s = "hello world";
        byte[] bytes1 = s.getBytes();
        fos.write(bytes1);
        //追加

        //关闭流
        fos.close();
    }
}
